package com.lpssfxy.statistics

import com.lpssfxy.statistics.utils.AppUtils
import org.apache.spark.SparkConf
import org.apache.spark.sql.SparkSession

object CountProductScoreByMonthMetrics {

  def main(args: Array[String]): Unit = {
    // 1. 准备环境
    val sparkConf = new SparkConf().setAppName(CountProductScoreByMonthMetrics.getClass.getSimpleName)//.setMaster(AppUtils.getMaster(args))
    val spark = SparkSession.builder().config(sparkConf).getOrCreate()
    // 2. 读取表数据创建DataFrame
    val ratingDF = AppUtils.readRatingAsDF(spark)
    // 3. 创建一张名叫ratings的表
    ratingDF.createOrReplaceTempView(AppUtils.DATAFRAME_TEMP_VIEW)
    // 4. 业务分析：统计所有历史数据中每个商品的评分数
    AppUtils.countProductScoreByMonth(spark)
    // 5. 关闭spark，释放资源
    spark.stop()
  }

}
